<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class SkuRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * validation rules for user
     *
     * @return array
     */
    public function rules()
    {
        return [
            'product_id' => 'required|exists:products,id',
            'quantity' => 'required|integer|min:1',
            'price' => 'required_if:type,0|numeric|min:0.01',
            'type' => 'required|in:0,1',
            'notes' => 'max:255'
        ];
    }

    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'product_id.required' => _("请选择物料"),
            'product_id.exists' => _("物料不存在"),
            'quantity.required'  => _("请输入进货量"),
            'quantity.integer'  => _("进货量为正整数"),
            'quantity.min'  => _("进货量必须为大于0"),
            'price.required_if' => _("请输入单位价格"),
            'price.numeric' => _("单位价格为数字"),
            'price.min'  => _("单位价格必须为大于0"),
            'type.required' => _("记录类型缺失"),
            'type.in' => _("记录类型信息有误")
        ];
    }
}
